﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using System.IO;

namespace HP.HierarchyWindow
{
    public static class ResourceUtil
    {
        public static ImageList LoadImageListStream(Type assemblyType, string imageName, Size imageSize, bool makeTransparent, Point transparentPixel)
        {
            // Create storage for bitmap strip
            ImageList images = new ImageList();

            // Define the size of images we supply
            images.ImageSize = imageSize;

            // Get the assembly that contains the bitmap resource
            Assembly myAssembly = Assembly.GetAssembly(assemblyType);

            // Get the resource stream containing the images
            Stream imageStream = myAssembly.GetManifestResourceStream(imageName);

            // Load the bitmap strip from resource
            Bitmap pics = new Bitmap(imageStream, true);

            if (makeTransparent)
            {
                Color backColor = pics.GetPixel(transparentPixel.X, transparentPixel.Y);

                // Make backColor transparent for Bitmap
                pics.MakeTransparent(backColor);
            }

            // Load them all !
            images.Images.AddStrip(pics);

            return images;
        }
    }
}
